from django.db import models
from control.models.User import User
import uuid
from .GlobalTables import KeywordType

# 关键词信息
class Keyword(models.Model): 
    uuid = models.UUIDField(primary_key = True,auto_created = True,default = uuid.uuid4,editable = False)
    k = models.CharField(verbose_name="关键词的键", max_length=400)		                          
    v = models.CharField(verbose_name="关键词键对应的值", max_length=400, null=True, blank=True)		    
    kt = models.ForeignKey(KeywordType, null=True, blank=True, verbose_name="所属类别", on_delete=models.CASCADE)
    is_reviewing = models.BooleanField(verbose_name="审核状态", default=False)

    creator = models.ForeignKey(User, verbose_name="创建者", related_name="keyword_creator", on_delete=models.CASCADE)				
    create_date = models.DateTimeField(verbose_name='创建时间', auto_now_add=True)
    last_editor = models.ForeignKey(User, verbose_name="最后编辑者", related_name="keyword_last_editor", on_delete=models.CASCADE)	
    last_edit_date = models.DateTimeField(verbose_name='最后编辑时间', auto_now=True)					
    reviewer = models.ForeignKey(User, verbose_name="审核者", related_name="keyword_reviewer", on_delete=models.CASCADE, null=True)
    review_date = models.DateTimeField(null=True, blank=True, verbose_name='审核时间')
    
    class Meta:
        ordering = ['-k', '-v', '-kt']
        verbose_name = "Keyword"           # 单数名称
        verbose_name_plural = "Keywords"   # 复数名称
        indexes = [
            models.Index(fields=['k', 'v'], name='final_query_idx_keyword')
        ]

    def __str__(self):
        return self.k